home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / filters.zip / FEED.ASM < prev    next >
Assembly Source File  |  1986-11-27  |  3KB  |  117 lines

  1.     Name feed
  2.     Title    feed
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that reads the parameter line
  7.     for a file spec.  If it finds one it opens all matching
  8.     files and sends them to standard output.  This is good
  9.     for processing more than one file, find, translat, etc.
  10. /
  11. ;===================================================================
  12. code    segment    public
  13. ;===================================================================
  14. ;
  15. ;    command line is at 80h of psp - first byte is length
  16. ;
  17.     org    80h
  18. ;parmsize    db    ?
  19. ;parm        db    7fh dup (?)
  20. dta    db    21 dup (?)
  21. attrib    db    ?
  22. ftime    dw    ?
  23. fdate    dw    ?
  24. fsize    dd    ?
  25. fname    db    13 dup (?)     ; dta asciiz filename from dos.
  26. ;
  27. ; .com starts at 100h - but must jump around any data area
  28. ;
  29.     org    100h            ; com file starts here
  30.     assume    cs:code,ds:code,es:code
  31. feed:
  32.     jmp    clear
  33. ;===================================================================
  34. ;
  35. ; data area for .com programs
  36. ;
  37. handle    dw    0h            ; assume standard input
  38. bufsiz    equ    255
  39. buffer    db    bufsiz dup (?)
  40. ;
  41. ;===================================================================
  42. clear:
  43. ;
  44. ; start of actual code is here (clear)
  45. ;
  46. ;
  47. ; now figure out which file to read from - parm line or standard input
  48. ;
  49.     cmp    dta,0h        ; if zero, no parm
  50.     jz    nomore        ; must have parm to read
  51. ;
  52. ; parm length is not zero - assume the parm is a file name.  If not
  53. ; found, quit.
  54. ;
  55.     mov    al,dta        ; get size of parm
  56.     xor    ah,ah        ; zero out top part of accum.
  57.     mov    si,ax        ; use length as a pointer into the dta
  58.     mov    [si]+dta+1,0h    ; to tack on a zero byte (asciiz).
  59. ;
  60. ; Use the default dta at 80h.  Find first matching filename.
  61. ;
  62.     lea    dx,dta+2    ; address of 'filename'
  63.     xor    cx,cx        ; attributes of file - (normal)
  64.     mov    ah,4Eh        ; dos
  65.     int    21h        ; invoke function
  66.     jc    nomore        ; error or no match - quit
  67. ;
  68. ; fname should now contain the first byte of an asciiz filename that
  69. ; matches the filespec from the parmline. open the file and send it
  70. ; to standard output.
  71. ;
  72. again:
  73. ;
  74. ; open the file
  75. ;
  76.     lea    dx,fname    ; point at asciiz filename
  77.     mov    al,0h        ; open for reading
  78.     mov    ah,3dh        ; read function call
  79.     int    21h        ; invoke dos
  80.     jc    oops
  81.     mov    handle,ax    ; save file handle.
  82. ;
  83. ; now use the handle to read the file.  AX will contain the # of
  84. ; characters returned from the file after the read.
  85. ; if ax=0 eof.
  86. ;
  87. readloop:
  88.     mov    bx,handle    ; read from standard input or file
  89.     mov    cx,bufsiz    ; # of characters to read
  90.     lea    dx,buffer    ; seg:off address of buffer area
  91.     mov    ah,3fh        ; dos read function
  92.     int    21h        ; invoke function
  93.     jc    oops        ; error!
  94.     cmp    ax,0h        ; if zero, end of file
  95.     jz    oops
  96. ;
  97.     mov    cx,ax        ; cx (and ax) contain # characters read
  98.     lea    si,buffer    ; offset of buffer
  99. ;
  100.     mov    bx,1h        ; standard output device
  101.     mov    ah,40h        ; dos write function
  102.     int    21h        ; invoke dos function
  103.  
  104.     jmp    readloop    ; repeat until end of file or error
  105. oops:
  106. ;
  107. ; end of file or access error
  108. ; jump to next filename
  109. ;
  110.     mov    ah,4fh        ; this call takes no input.
  111.     int    21h        ; if carry set, no more files.
  112.     jnc    again       ; if no carry, go transfer this one
  113. nomore:
  114.     int    20h        ; return to dos
  115. code    ends
  116.     end    feed
  117.